package com.bsj.power.common.config.cached;

import com.alibaba.fastjson2.JSON;
import com.bsj.power.common.config.redis.RedisConstant;
import com.bsj.power.common.def.entity.job.WorkPersonnel;
import com.bsj.power.common.def.entity.personnel.Personnel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import redis.clients.bsj.JedisClusterBSJ;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description 作业人员缓存
 * @time 2024/7/17 15:57
 */
@Component
public class WorkPersonnelCached {

    @Autowired
    private RedisCached redisCached;

    /**
     * 获取作业人员信息
     *
     * @param temporaryEmpNo
     * @return com.bsj.power.common.def.entity.job.WorkPersonnel
     * @author ljx
     * @time 2024/7/17 16:01
     */
    public WorkPersonnel getWorkPersonnelInfo(String temporaryEmpNo) {
        String str = redisCached.get(RedisConstant.WORK_PERSONNEL_REDIS_KEY + temporaryEmpNo);
        if (str == null) {
            return null;
        }
        return JSON.parseObject(str, WorkPersonnel.class);
    }

    /**
     * 缓存作业人员信息
     *
     * @param workPersonnel
     * @return void
     * @author ljx
     * @time 2024/7/17 16:32
     */
    public void setWorkPersonnelInfo(WorkPersonnel workPersonnel) {
        if (workPersonnel != null) {
            redisCached.set(RedisConstant.WORK_PERSONNEL_REDIS_KEY + workPersonnel.getTemporaryEmpNo(), workPersonnel);
        }
    }

    /**
     * 删除作业人员信息
     *
     * @param temporaryEmpNo
     * @return void
     * @author ljx
     * @time 2024/7/17 16:35
     */
    public void delWorkPersonnelInfo(String temporaryEmpNo) {
        redisCached.del(RedisConstant.WORK_PERSONNEL_REDIS_KEY + temporaryEmpNo);
    }

}
